﻿/*

The MIT License

Copyright (c) 2010 Cartesian Analytics, Inc. 

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/

using System;
using System.Collections.Generic;
using Pipra.Math;

namespace Pipra.Uom
{
    /// <summary>
    /// A base class for a generic value converter.
    /// </summary>
    public abstract class ValueConverterBase :
        IValueConverter<double>
    {
        /// <summary>
        /// The unit type.
        /// </summary>
        public readonly string Type;
        /// <summary>
        /// The unit to convert from.
        /// </summary>
        public readonly IUom From;
        /// <summary>
        /// The unit to convert to.
        /// </summary>
        public readonly IUom To;
        /// <summary>
        /// Initialized the converter base.
        /// </summary>
        /// <param name="type">The unit type.</param>
        /// <param name="from">The unit the converter converts from.</param>
        /// <param name="to">The unit the converter converts to.</param>
        protected ValueConverterBase(string type, IUom from, IUom to)
        {
            Type = type;
            From = from;
            To = to;
        }

        string IValueConverter.Type
        {
            get { return Type; }
        }

        IUom IValueConverter.From
        {
            get { return From; }
        }

        IUom IValueConverter.To
        {
            get { return To; }
        }

        public abstract int OpCost { get; }

        public abstract double TransformValue(double value);

        [CLSCompliant(false)]
        public abstract void TransformValue(ref double value);

        public abstract void TransformValues(double[] values);

        public abstract IEnumerable<double> TransformValues(IEnumerable<double> values);

        public abstract bool HasInverse { get;} 

        ITransformation<double> ITransformation<double>.GetInverse()
        {
            return GetInverse();
        }
        
        ITransformation<double, double> ITransformation<double, double>.GetInverse()
        {
            return GetInverse();
        }

        ITransformation ITransformation.GetInverse()
        {
            return GetInverse();
        }

        IValueConverter IValueConverter.GetInverse()
        {
            return GetInverse();
        }

        public abstract IValueConverter<double> GetInverse();

    }
}
